import 'package:flutter/material.dart';
import 'dart:math';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  static final String title = "Material App";
  GlobalKey<_HYHomePageState> globalKey = GlobalKey();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Material App',
        home: HYHomePage(key:globalKey)

    );
  }
}

class HYHomePage extends StatefulWidget {

  HYHomePage({Key key}): super(key: key);
  @override
  _HYHomePageState createState() => _HYHomePageState();
}

class _HYHomePageState extends State<HYHomePage> {

  List<String> names = ["aaa", "bbb", "ccc"];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(MyApp.title),
      ),
      body: ListView(
        children: names.map((name) {
          return ListItemFul(name,key:UniqueKey());
        }).toList(),
      ),

      floatingActionButton: FloatingActionButton(
          child: Icon(Icons.delete),
          onPressed: () {
            setState(() {
              names.removeAt(0);
            });
          }
      ),
    );
  }
}

class ListItemLess extends StatelessWidget {
  final String name;
  final Color randomColor = Color.fromARGB(255, Random().nextInt(256), Random().nextInt(256), Random().nextInt(256));

  ListItemLess(this.name);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60,
      child: Text(name,style: TextStyle(fontSize: 30,color: Colors.white),),
      color: randomColor,
    );
  }
}

class ListItemFul extends StatefulWidget {
  final String name;

  ListItemFul(this.name, {Key key}): super(key: key);

  @override
  _ListItemFulState createState() => _ListItemFulState();
}

class _ListItemFulState extends State<ListItemFul> {
  final Color randomColor = Color.fromARGB(255, Random().nextInt(256), Random().nextInt(256), Random().nextInt(256));

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60,
      child: Text(widget.name,style: TextStyle(fontSize: 30,color: Colors.white),),
      color: randomColor,
    );
  }
}